<template>
  <view class="container">
    <view v-for="(item, id) in leaveList" :key="item.id" class="leave-item">
      <view class="leave-info" @click="toaskforDetail(item.id)">
        <view class="info-item">请假开始时间：{{ item.leaveTimeStart }}</view>
        <view class="info-item">请假结束时间：{{ item.leaveTimeEnd }}</view>
        <view class="info-item" v-html="'请假说明：'+item.leaveDetailes"></view>
        <view class="info-item">老师电话：{{ item.usersNickTelephone }}</view>
        <view class="info-item">学生姓名：{{ item.studentName }}</view>
        <view class="info-item">学生电话：{{ item.studentTelephone }}</view>
        <view class="info-item">发病症状：{{ item.onsetSymptoms }}</view>
        <view class="info-item">诊断疾病：{{ item.diagnose }}</view>
        <view class="info-item">诊断日期：{{ item.diagnosisTime }}</view>
        <view class="info-item">发病日期：{{ item.morbidityTime }}</view>
        <view class="info-item">请假类型：{{ item.leaveType === 1 ? '事假' : '病假' }}</view>
        <view class="info-item">离校状态：{{ item.state === 1? '已离校' : '未离校' }}</view>
        <view class="info-item">删除状态：{{ item.isDetele === 1 ? '未删除' : '已删除' }}</view>
      </view>
    </view>
	<uni-fab ref="fab" horizontal="right" vertical="bottom" direction="horizontal" @fabClick="toAddAskfor"/>
  </view>
</template>

<script>
export default {
  data() {
    return {
      leaveList: []
    };
  },
  mounted() {
    this.fetchLeaveList();
  },
  methods: {
	  toAddAskfor(){
	  	uni.navigateTo({
	  		url:'/pages/askfor/addaskfor'
	  	})
	  },
	  toaskforDetail(id){
		uni.navigateTo({
			url:'/pages/askfor/askforDetail?id='+id
		})  
	  },
  //   fetchLeaveList() {
  //     uni.request({
  //       url: 'https://www.gzzyue.com/prod-api/system/leaveManagement/list',
  //       method: 'GET',
		// header: {
		// 	'Authorization': uni.getStorageSync("token") //自定义请求头信息
		// },
  //       success: res => {
  //         console.log('res:', res);
  //         if (res.statusCode === 200) {
  //           this.leaveList = res.data.data;
  //         } else {
  //           uni.showToast({
  //             title: '获取数据失败',
  //             icon: 'none'
  //           });
  //         }
  //       },
  //       fail: error => {
  //         console.log('error:', error);
  //         uni.showToast({
  //           title: '请求接口失败',
  //           icon: 'none'
  //         });
  //       }
  //     });
  //   },
	 fetchLeaveList(){
		uni.request({
			 url: 'https://www.gzzyue.com/prod-api/system/leaveManagement/list',
			method: 'GET',
			header: {
				'Authorization': uni.getStorageSync("token") //自定义请求头信息
			},
			success: (res) => {
				console.log('res:', res);
				if (res.statusCode == 200) {
					if (res.data.code == 200) {
						
						 this.leaveList = res.data.rows.reverse();
						
					} else if (res.data.code == 500) {
						uni.$u.toast(res.data.msg)
					} else {
						uni.$u.toast('系统服务异常，请联系管理员！')
					}
				} else {
					uni.$u.toast('系统服务异常，请联系管理员！')
				}
			},
			fail: (errors) => {
				console.log('errors:', errors);
				uni.$u.toast('服务器错误，请联系管理员！')
			},
		});
	},
  }
};
</script>

<style scoped>
.container {
  padding: 20rpx;
  background-color: #f2f2f2;
}


.leave-item {
  margin-bottom: 20rpx;
  border: none;
  box-shadow: 0 2rpx 5rpx rgba(0, 0, 0, 0.1);
  background-color: #fff;
  border-radius: 5rpx;
  padding: 10rpx;
}


.info-item {
  margin-bottom: 8rpx;
}
.uni-fab {
  position: fixed;
  right: 20rpx;
  bottom: 20rpx;
}
.uni-fab .uni-icons {
  color: #fff;
}

.uni-fab {
  background-color: #007aff;
}

</style>
